﻿from appium import webdriver
from appium.webdriver.common.appiumby import By
from time import sleep
from swipe import *
from appium.webdriver.common.touch_action import TouchAction

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '7'
desired_caps['deviceName'] = '127.0.0.1:62001'
desired_caps['app'] = r'e:\SoftWare\apk\mymoney.apk'
desired_caps['appPackage'] = r'com.mymoney'
desired_caps['appActivity'] = r'com.mymoney.biz.splash.SplashScreenActivity'
desired_caps['noReset'] = False  # False代表重置（重新安装），默认值就是False

driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
driver.implicitly_wait(10)  # 隐式等待
sleep(3)

# 点击同意
driver.find_element(By.ID, 'com.mymoney:id/sui_dialog_positive_btn_style1').click()
# 点击选账本
driver.find_element(By.ID, 'com.mymoney:id/select_template_btn').click()
# 点击跳过
driver.find_element(By.ID, 'com.mymoney:id/bottom_skip_tv').click()
sleep(5)
# 点击我的
driver.find_element(By.ID, 'com.mymoney:id/account_centre_icon_default_iv').click()

driver.implicitly_wait(15)
driver.find_element(By.ID, 'com.mymoney:id/account_centre_icon_default_iv').click()
sleep(3)
# 滑动到底部
for i in range(2):
    swipe_to_up(driver)
sleep(3)
# 点击设置
driver.find_element(By.XPATH,
                    '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout'
                    '/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/androidx'
                    '.viewpager.widget.ViewPager/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout'
                    '/android.widget.LinearLayout/android.widget.ScrollView/android.widget.LinearLayout/androidx'
                    '.recyclerview.widget.RecyclerView/android.widget.FrameLayout['
                    '9]/android.widget.LinearLayout/android.widget.TextView').click()
# 密码保护
driver.find_element(By.CLASS_NAME, 'android.view.ViewGroup').click()
# 点击开启按钮
driver.find_element(By.XPATH,
                    '/ hierarchy / android.widget.FrameLayout / android.widget.LinearLayout / '
                    'android.widget.FrameLayout / android.widget.FrameLayout / android.widget.FrameLayout / '
                    'android.widget.FrameLayout / android.widget.LinearLayout / android.widget.LinearLayout / '
                    'android.widget.LinearLayout / android.view.ViewGroup / android.widget.Switch').click()
# 点击手势密码
driver.find_element(By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget'
                              '.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget'
                              '.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget'
                              '.LinearLayout[2]/android.widget.LinearLayout[1]/android.widget.TextView').click()
sleep(2)
# 滑动
for i in range(2):
    TouchAction(driver).press(x=255, y=385).wait(1000).move_to(x=445, y=385).wait(1000).move_to(x=645, y=385).wait(
        1000).move_to(x=645, y=585).wait(1000).move_to(x=645, y=775).wait(1000).move_to(x=245, y=585).wait(
        1000).release().perform()
sleep(3)

driver.quit()
